//
//  MLTabBarController.swift
//  MLWeiBo
//
//  Created by wenxing on 2017/1/4.
//  Copyright © 2017年 Se7venX. All rights reserved.
//

import UIKit

class MLTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //tabBar
        let tabBar = MLTabBar()

        self.setValue(tabBar, forKey: "tabBar")
        
        
        tabBar.composeClosure = {
        
            print("点击了+")
            
            
            let window = UIApplication.shared.keyWindow!
            
            
            let composeView = MLComposeView(frame:window.bounds )
            
            
            window.addSubview(composeView)
            
            
            
        }
    
        
        addChildViewControllers(vc: MLHomeViewController(), title: "首页", imgaeName: "tabbar_home")
        addChildViewControllers(vc:MLMessageViewController(), title: "信息", imgaeName: "tabbar_message_center")
        addChildViewControllers(vc: MLDiscoverViewController(), title: "发现", imgaeName: "tabbar_discover")
        addChildViewControllers(vc: MLProfileViewController(), title: "我的", imgaeName: "tabbar_profile")
    
    }

    //MARK:- UITableViewDataSource
    func addChildViewControllers(vc:UIViewController,title:String,imgaeName:String){
    
        let homevc = vc   //MLHomeViewController()
        
        
        //文字
        homevc.tabBarItem.title = title
        homevc.navigationItem.title = title
        
        //图片
        homevc.tabBarItem.image = UIImage(named: imgaeName)
        homevc.tabBarItem.selectedImage =
            UIImage(named:imgaeName+"_selected")!.withRenderingMode(.alwaysOriginal)
    
        //配置颜色、字体
//        homevc.tabBarItem.setTitleTextAttributes([NSFontAttributeName:UIFont.systemFont(ofSize: 10)], for: .normal)
        homevc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orange], for: .selected)
        
        //设置文字偏移
//        homevc.tabBarItem.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: 5)
        
        //设置图片的偏移
//        homevc.tabBarItem.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0)
        
        
        //数标
//        homevc.tabBarItem.badgeValue = "10"
//        homevc.tabBarItem.badgeColor = #colorLiteral(red: 0.2196078449, green: 0.007843137719, blue: 0.8549019694, alpha: 1)
//        homevc.tabBarItem.badgeValue = nil

   
        
        let nav = MLNavController(rootViewController: homevc)
        
        addChildViewController(nav)
        
        
    }
    
}
